using UnityEngine;
public class EnterCar : MonoBehaviour
{
    public RoleInfo car;
    public RoleInfo player;
    public bool isInCar = false; // 标记玩家是否在车内

    void Awake()
    {
        car = transform.parent.GetComponent<RoleInfo>();
    }

    /// <summary>上车</summary>
    public void InCar(RoleInfo role)
    {
        if (isInCar) return;
        player = role;
        player.transform.SetParent(car.transform); // 将玩家变成汽车的子节点
        player.gameObject.SetActive(false); // 隐藏玩家
        GameManager.ins.SetPlayer(car);
        isInCar = true;
    }
    /// <summary>下车</summary>
    public void ExitCar()
    {
        player.transform.SetParent(null); // 将玩家从汽车的子节点中移除
        player.gameObject.SetActive(true); // 显示玩家
        GameManager.ins.SetPlayer(player);
        isInCar = false;
    }
}